home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
ORBMECHD
/
ORBMECH1.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-30
|
11KB
|
539 lines
/*******************************************
Orbital Mechanics Application
Copyright Karl Dishaw 1990
Version 0.0.1d
5 Jan 90
Version 0.1.0d
17 Jul 90
Version 0.5d
22 Oct 90
Version 0.9a
18 Feb 91
Version 0.95a
12 Jun 91
Version 0.96a
27 Jun 91
Written in Symantec Think C
********************************************/
#include "orbmech.h"
#include "SANE.h"
#include "math.h"
/* globals */
EventRecord gEvent;
Boolean gifWNE, gDone = 1, gWriting = 0;
DialogPtr LambertDia, HohmannDia, HillsDia, KeplerDia, whichDialog, gHelpDia;
DialogPtr gLamHelpDia, gHillsHelpDia, gKepHelpDia, gHohHelpDia;
Rect gDragRect;
Cursor gEditCursor, gWaitCursor;
WindowRecord wRecord;
WindowPtr myWindow;
TEHandle TEH;
int dirty = 0;
ControlHandle vScroll;
MenuHandle myMenus[6];
Boolean dialogEvent;
decform gdecform;
extern Str255 gFileName;
struct ParamRec
{
extended value;
Str255 name;
} gParameter;
/********************/
main()
{
ToolBoxInit();
AppInits();
MaxApplZone();
MoreMasters();
MoreMasters();
MoreMasters();
MoreMasters();
gifWNE = ( NGetTrapAddress( WNE_TRAP_NUM, ToolTrap )
!= NGetTrapAddress( UNIMPL_TRAP_NUM, ToolTrap ) );
while ( gDone != FALSE )
{
EventLoop();
}
}
/************ Tool Box Init ********/
ToolBoxInit()
{
InitGraf( &thePort );
InitFonts();
FlushEvents( everyEvent, REMOVE_ALL_EVENTS );
InitWindows();
InitMenus();
TEInit();
InitDialogs( NIL_POINTER );
InitCursor();
gdecform.style = FLOATDECIMAL;
gdecform.digits = 8;
}
/**************************/
AppInits()
{
MenuBarInit();
WindowInit();
SetUpCursors();
SetUpDragRect();
SetUpFiles();
DlgInits();
gParameter.value = EARTH_CONSTANT;
pStrCopy("\pEarth", gParameter.name);
CheckItem( myMenus[PARAMETER_MENU], EARTH, TRUE);
gdecform.style = FLOATDECIMAL;
gdecform.digits = 8;
}
/**************************/
SetUpCursors()
{
CursHandle hCurs;
hCurs = GetCursor(3);
gEditCursor = **hCurs;
hCurs = GetCursor(watchCursor);
gWaitCursor = **hCurs;
}
/***************************/
SetUpDragRect()
{
gDragRect = screenBits.bounds;
gDragRect.left += DRAG_THRESHOLD;
gDragRect.right -= DRAG_THRESHOLD;
gDragRect.bottom -= DRAG_THRESHOLD;
}
/*****************************/
MenuBarInit()
{
Handle myMenuBar;
myMenuBar = GetNewMBar( 1000 );
SetMenuBar( myMenuBar );
myMenus[0] = GetMHandle( APPLE_MENU_ID );
AddResMenu( myMenus[0], 'DRVR' );
myMenus[1] = GetMHandle( FILE_MENU_ID );
myMenus[2] = GetMHandle( EDIT_MENU_ID );
myMenus[3] = GetMHandle( CALCULATIONS_MENU_ID );
myMenus[4] = GetMHandle( TUTORIALS_MENU_ID );
myMenus[5] = GetMHandle( PARAMETER_MENU_ID );
DrawMenuBar();
}
/********************/
EventLoop()
{
char theChar;
int itemHit;
Rect r;
WindowPtr whichWindow;
if ( gifWNE )
WaitNextEvent( everyEvent, &gEvent, MIN_SLEEP, NIL_MOUSE_REGION );
else
{
SystemTask();
GetNextEvent( everyEvent, &gEvent );
}
dialogEvent = IsDialogEvent( &gEvent );
if ( dialogEvent && ( (gEvent.modifiers & cmdKey) == 0 ))
{
DialogSelect( &gEvent, &whichDialog, &itemHit );
if ( ( whichDialog ) == LambertDia )
HandleLambert( itemHit );
if ( ( whichDialog ) == HohmannDia )
HandleHohmann( itemHit );
if ( ( whichDialog ) == HillsDia )
HandleHills( itemHit );
if ( ( whichDialog ) == KeplerDia )
HandleKepler( itemHit );
if ( ( whichDialog ) == gHelpDia )
HandleHelp( itemHit );
if ( ( whichDialog ) == gLamHelpDia )
HandleLamHelp( itemHit );
if ( ( whichDialog ) == gHillsHelpDia )
HandleHillsHelp( itemHit );
if ( ( whichDialog ) == gKepHelpDia )
HandleKepHelp( itemHit );
if ( ( whichDialog ) == gHohHelpDia )
HandleHohHelp( itemHit );
if ( FindWindow( gEvent.where, &whichWindow ) == inMenuBar )
return( DoCommand( MenuSelect(gEvent.where) ) );
}
if ((gEvent.modifiers & cmdKey) != 0 && ( gEvent.what == keyDown ) )
return( DoCommand( MenuKey( gEvent.message & charCodeMask ) ));
if ( !dialogEvent )
{
switch ( gEvent.what )
{
case mouseDown:
HandleMouseDown();
break;
case keyDown:
case autoKey:
{
register char theChar;
theChar = gEvent.message & charCodeMask;
if ((gEvent.modifiers & cmdKey) != 0)
return( DoCommand( MenuKey( theChar ) ));
else
{
if ( gWriting && !dialogEvent )
{
TEKey( theChar, TEH );
ShowSelect();
dirty = 1;
}
}
}
break;
case activateEvt:
/* if (ours((WindowPtr)gEvent.message)) */
{
r=(*myWindow).portRect;
r.top = r.bottom - (S_BAR_WIDTH+1);
r.left = r.left - (S_BAR_WIDTH+1);
InvalRect(&r);
if ( gEvent.modifiers & activeFlag ) {
TEActivate( TEH );
gWriting = 1;
ShowControl( vScroll );
}
else {
TEDeactivate(TEH);
gWriting = 0;
HideControl( vScroll );
}
}
break;
case updateEvt:
/* if (ours((WindowPtr)gEvent.message)) */
UpdateWindow(myWindow);
break;
case nullEvent:
break;
}
}
MaintainMenus();
}
/***************************/
HandleMouseDown()
{
WindowPtr whichWindow;
switch (FindWindow( gEvent.where, &whichWindow ))
{
case inSysWindow:
SystemClick( &gEvent, whichWindow );
break;
case inDrag:
DragWindow( whichWindow, gEvent.where, &gDragRect);
break;
case inGoAway:
if (TrackGoAway( myWindow, gEvent.where) )
DoFile( CLOSE_FILE );
break;
case inMenuBar:
return( DoCommand( MenuSelect(gEvent.where) ) );
case inGrow:
MyGrowWindow( whichWindow, gEvent.where );
break;
case inContent:
if (whichWindow != FrontWindow())
SelectWindow(whichWindow);
else
DoContent(whichWindow, &gEvent);
break;
}
}
ours(w)
WindowPtr w;
{
return( (myWindow!=NULL) && (w==myWindow) );
}
/**********************************/
int DoCommand( mResult )
long mResult;
{
int theItem, temp, accNumber;
Str255 accName;
WindowPeek wPtr;
theItem = LoWord( mResult );
switch (HiWord(mResult)) {
case APPLE_MENU_ID:
switch(theItem)
{
case ABOUT_ITEM:
Alert( ABOUT_ALERT, NIL_POINTER);
break;
default:
GetItem( myMenus[0], theItem, accName );
accNumber = OpenDeskAcc( accName );
break;
}
break;
case FILE_MENU_ID:
DoFile(theItem);
break;
case EDIT_MENU_ID:
DoEdit(theItem);
break;
case CALCULATIONS_MENU_ID:
DoCalcMenu( theItem );
break;
case TUTORIALS_MENU_ID:
DoTutMenu( theItem );
break;
case PARAMETER_MENU_ID:
DoParameter( theItem );
break;
}
HiliteMenu(0);
return(1);
}
/********************************/
DoEdit(theItem)
int theItem;
{
WindowPeek wPtr;
if (SystemEdit(theItem-1)==0) {
wPtr = (WindowPeek) FrontWindow();
switch (theItem)
{
case CUT_COMMAND:
if( !dialogEvent ) {
TECut( TEH );
ZeroScrap();
TEToScrap();
dirty = 1;
}
else {
DlgCut( whichDialog );
ZeroScrap();
TEToScrap();
}
break;
case COPY_COMMAND:
if( !dialogEvent ) {
TECopy( TEH );
ZeroScrap();
TEToScrap();
}
else {
DlgCopy( whichDialog );
ZeroScrap();
TEToScrap();
}
break;
case PASTE_COMMAND:
if( !dialogEvent ) {
TEFromScrap();
TEPaste( TEH );
dirty = 1;
}
else {
TEFromScrap();
DlgPaste( whichDialog );
}
break;
/** case CLEAR_COMMAND:
if( !dialogEvent ) {
TEDelete( TEH );
}
else DlgDelete( whichDialog );
dirty = 1;
break; **/
default: ;
}
ShowSelect();
}
}
/******************************/
DoParameter( theItem )
int theItem;
{
SetItemMark( myMenus[PARAMETER_MENU], EARTH, 0 );
SetItemMark( myMenus[PARAMETER_MENU], SUN, 0 );
switch ( theItem )
{
case 1:
gParameter.value = EARTH_CONSTANT;
pStrCopy("\pEarth", gParameter.name);
CheckItem( myMenus[PARAMETER_MENU], EARTH, TRUE);
break;
case 2:
gParameter.value = SUN_CONSTANT;
pStrCopy("\pSun", gParameter.name);
CheckItem( myMenus[PARAMETER_MENU], SUN, TRUE);
break;
}
}
pascal void ScrollProc(theControl, theCode)
ControlHandle theControl;
int theCode;
{
int pageSize;
int scrollAmt;
if (theCode == 0)
return ;
pageSize = ((**TEH).viewRect.bottom-(**TEH).viewRect.top) /
(**TEH).lineHeight - 1;
switch (theCode) {
case inUpButton:
scrollAmt = -1;
break;
case inDownButton:
scrollAmt = 1;
break;
case inPageUp:
scrollAmt = -pageSize;
break;
case inPageDown:
scrollAmt = pageSize;
break;
}
SetCtlValue( theControl, GetCtlValue(theControl)+scrollAmt );
AdjustText();
}
DoContent(theWindow, theEvent)
WindowPtr theWindow;
EventRecord *theEvent;
{
int cntlCode;
ControlHandle theControl;
int pageSize;
GrafPtr savePort;
GetPort(&savePort);
SetPort(theWindow);
GlobalToLocal( &theEvent->where );
if ((cntlCode = FindControl(theEvent->where, theWindow, &theControl)) == 0) {
if (PtInRect( theEvent->where, &(**TEH).viewRect ))
TEClick( theEvent->where, (theEvent->modifiers & shiftKey )!=0, TEH);
}
else if (cntlCode == inThumb) {
TrackControl(theControl, theEvent->where, 0L);
AdjustText();
}
else
TrackControl(theControl, theEvent->where, &ScrollProc);
SetPort(savePort);
}
/***************************/
MaintainMenus()
{
MenuHandle temp;
if ( !(*(WindowPeek)myWindow).visible ||
!ours(FrontWindow()) ) {
EnableItem( myMenus[FILE_MENU], NEW_FILE );
EnableItem( myMenus[FILE_MENU], OPEN_FILE );
DisableItem( myMenus[FILE_MENU], CLOSE_FILE );
DisableItem( myMenus[FILE_MENU], SAVE_FILE );
DisableItem( myMenus[FILE_MENU], SAVE_AS );
DisableItem( myMenus[FILE_MENU], REVERT_FILE );
EnableItem( myMenus[EDIT_MENU], CUT_COMMAND );
EnableItem( myMenus[EDIT_MENU], COPY_COMMAND );
/* EnableItem( myMenus[EDIT_MENU], clearCommand ); */
}
else {
DisableItem( myMenus[FILE_MENU], NEW_FILE );
DisableItem( myMenus[FILE_MENU], OPEN_FILE );
EnableItem( myMenus[FILE_MENU], CLOSE_FILE );
EnableItem( myMenus[FILE_MENU], SAVE_AS );
if (dirty && gFileName[0] != 0) {
EnableItem( myMenus[FILE_MENU], REVERT_FILE );
EnableItem( myMenus[FILE_MENU], SAVE_FILE );
}
else {
DisableItem( myMenus[FILE_MENU], REVERT_FILE );
DisableItem( myMenus[FILE_MENU], SAVE_FILE );
}
if ((**TEH).selStart==(**TEH).selEnd) {
DisableItem( myMenus[EDIT_MENU], CUT_COMMAND );
DisableItem( myMenus[EDIT_MENU], COPY_COMMAND );
/* DisableItem( myMenus[EDIT_MENU], clearCommand ); */
}
else {
EnableItem( myMenus[EDIT_MENU], CUT_COMMAND );
EnableItem( myMenus[EDIT_MENU], COPY_COMMAND );
/* EnableItem( myMenus[EDIT_MENU], clearCommand ); */
}
}
}